use chrono::{DateTime, Duration, Utc};
use rand::Rng;
use rand::seq::SliceRandom;
use serde_json::Value;
use super::*;

// 中文姓名生成器
pub struct ZhNameGenerator;

impl Generator for ZhNameGenerator {
    fn generate(&self) -> Value {
        let surnames = ["王", "李", "张", "刘", "陈", "杨", "赵", "黄", "周", "吴"];
        let given_names = ["伟", "芳", "娜", "强", "敏", "静", "丽", "勇", "艳", "涛"];
        let name = format!(
            "{}{}",
            surnames.choose(&mut rand::thread_rng()).unwrap(),
            given_names.choose(&mut rand::thread_rng()).unwrap()
        );
        Value::String(name)
    }
}

// 英文姓名生成器
pub struct EnNameGenerator;

impl Generator for EnNameGenerator {
    fn generate(&self) -> Value {
        let first_names = ["John", "Jane", "Michael", "Sarah", "David", "Emily", "Robert", "Lisa"];
        let last_names = ["Smith", "Johnson", "Williams", "Brown", "Jones", "Garcia", "Miller", "Davis"];
        
        let mut rng = rand::thread_rng();
        let first = first_names.choose(&mut rng).unwrap();
        let last = last_names.choose(&mut rng).unwrap();
        
        Value::String(format!("{} {}", first, last))
    }
}

// 日期时间范围生成器
pub struct DateTimeRangeGenerator {
    start: DateTime<Utc>,
    end: DateTime<Utc>,
}

impl DateTimeRangeGenerator {
    pub fn new(start: DateTime<Utc>, end: DateTime<Utc>) -> Self {
        Self { start, end }
    }
}

impl Generator for DateTimeRangeGenerator {
    fn generate(&self) -> Value {
        let secs = self.end.timestamp() - self.start.timestamp();
        let random_secs = rand::thread_rng().gen_range(0..secs);
        let dt = self.start + Duration::seconds(random_secs);
        Value::String(dt.to_rfc3339())
    }
}

// UUID生成器
pub struct UuidGenerator;

impl Generator for UuidGenerator {
    fn generate(&self) -> Value {
        Value::String(uuid::Uuid::new_v4().to_string())
    }
}

// 邮箱生成器
pub struct EmailGenerator;

impl Generator for EmailGenerator {
    fn generate(&self) -> Value {
        let domains = ["gmail.com", "yahoo.com", "hotmail.com", "163.com", "qq.com"];
        let mut rng = rand::thread_rng();
        
        let username = format!("user{}", rng.gen_range(1000..9999));
        let domain = domains.choose(&mut rng).unwrap();
        
        Value::String(format!("{}@{}", username, domain))
    }
}

